package com.zeus.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

@Controller
public class IndexController {

//    @Value("classpath:init.json")
//    private Resource resource;

    @RequestMapping("/index")
    public String index() {
        return "index";
    }

    @GetMapping("/info")
    public String info(){
        return "info";
    }
//解析init.json,为了防止客户端可以通过路径直接就看到我们网页里json，具体操作就是把init.json从web目录下转移到resource,再用注解加载，然后封装到这个类里面
//    @GetMapping("/menu")
//    @ResponseBody
//    public void menu(HttpServletResponse response) {
//        try {
//            File file = resource.getFile();
//            FileReader fileReader = new FileReader(file);
//            BufferedReader bufferedReader = new BufferedReader(fileReader);
//            String str;
//            StringBuffer sb = new StringBuffer();
//            while ((str = bufferedReader.readLine()) !=null){
//                sb.append(str);
//            }
//            bufferedReader.close();
//            fileReader.close();
//            response.setContentType("application/json;charset=utf-8");
//            response.getWriter().print(sb.toString());
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }


}
